package com.astoolkit.workflow.common
{
	import com.astoolkit.workflow.BaseTask;
	
	import flash.utils.getQualifiedClassName;
	import flash.utils.setTimeout;
	
	import mx.logging.ILogger;
	import mx.logging.Log;
	import mx.logging.LogEventLevel;

	public class WriteLog extends BaseTask
	{

		private static const LOGGER : ILogger = 
			Log.getLogger( getQualifiedClassName( WriteLog ).replace(/:+/g, "." ) );
		
		public var message : String = "[REPLACE ME]";
		public var parameters : Array = [];
		
		[Inspectable(defaultValue="debug", enumeration="debug,info,warn,error,fatal")]
		public var level : String = "debug";
		
		private var _levels : Object =
			{
				debug : LogEventLevel.DEBUG,
				info : LogEventLevel.INFO,
				warn : LogEventLevel.WARN,
				error : LogEventLevel.ERROR,
				fatal : LogEventLevel.FATAL
			};
		
		override public function begin() : void
		{
			super.begin();
			var args : Array = [ _levels[ level ], message ];
			args = args.concat( parameters );
			
			if( LOGGER )
			{
				var logFn : Function  = LOGGER[ "log" ] as Function;
				if( logFn != null )
					logFn.apply( LOGGER, args );
			}
			complete();
		}		
	}
}